<template>
  <div class="app-container">
    <div class="filter-container">
      <span>订单编号：</span>
      <el-input
        v-model="paramOrder.orderSn"
        placeholder="请输入订单编号"
        style="width: 200px"
        class="filter-item"
      />
      <span class="leftMar">收件人：</span>
      <el-input
        v-model="paramOrder.addressee"
        placeholder="请输入收件人"
        style="width: 200px"
        class="filter-item"
      />
      <span class="leftMar">订单状态：</span>
      <el-select v-model="paramOrder.status" clearable placeholder="请选择">
        <el-option
          v-for="item in orderStatus"
          :key="item.key"
          :label="item.value"
          :value="item.key"
        >
        </el-option>
      </el-select>
      <span class="leftMar">时间选择：</span>
      <el-date-picker
        v-model="paramOrder.time"
        type="daterange"
        value-format="yyyy-MM-dd HH:mm:ss"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      >
      </el-date-picker>
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="search"
      >
        搜索
      </el-button>
    </div>
    <el-table
      :data="dataList"
      v-loading="listLoading"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="序号" width="80" align="center">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="日期" width="200" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.paymentTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单编号" width="200" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.orderSn }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收件人" width="100" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.addressee }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收件地址" width="250" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.address }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电话号" width="150" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.phone || "无" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="金额" width="80" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.totalAmount + "元" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="120" align="center">
        <template slot-scope="{ row }">
          <el-tag :type="row.status | statusVal('type')">{{
            row.status | statusVal("value")
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :page-size="10"
      :total="total_size"
      @current-change="changePage"
    >
    </el-pagination>
  </div>
</template>

<script>
import { orderStatus } from "@/config/index";
import { GetOrderList } from "@/api/order";
export default {
  name: "indent",
  data() {
    return {
      orderStatus, //订单状态
      total_size: 0, //多少条数据
      paramOrder: {
        //订单查询条件
        currPage: 1,
        pageSize: 10,
        orderSn: "",
        addressee: "",
        status: "",
        time: ["", ""],
      },
      value1: "",
      listLoading: true, //加载
      dataList: [], //数据
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    search() {
      this.getOrderList();
    },
    changePage(page) {
      console.log(page);
      this.paramOrder.currPage = page;
      this.getOrderList();
    },
    //获取订单列表
    getOrderList() {
      GetOrderList(this.paramOrder).then((res) => {
        this.total_size = Number(res.data.total_size);
        this.dataList = res.data.data_list;
        this.listLoading = false;
      });
    },
  },
  filters: {
    statusVal(value, key = "value") {
      for (let val of orderStatus) {
        if (value == val.key) {
          return val[key];
        }
      }
      let data = { value: "未知", color: "back", type: "info" };
      return data[key];
    },
  },
};
</script>
<style scoped>
.leftMar {
  margin-left: 8px;
}
.filter-container {
  margin-bottom: 10px;
}
</style>